{itemplate 'public/header'}
<form action="./index.php?" class="form-horizontal form-filter" id="form-takeout">
	{php echo tpl_form_filter_hidden('order/tangshi/list');}
	<input type="hidden" name="filter_type" value="{$filter_type}"/>
	{if $filter_type == 'process' || $filter_type == 'all'}
		<input type="hidden" name="status" value="{$status}"/>
		<input type="hidden" name="pay_type" value="{$pay_type}"/>
		<div class="form-group">
			<label class="col-xs-12 col-sm-3 col-md-2 control-label">订单状态</label>
			<div class="col-sm-9 col-xs-12">
				<div class="btn-group">
					<div class="btn-group">
						<a href="{php echo ifilter_url('status:0');}" class="btn {if $status == 0}btn-primary{else}btn-default{/if}">不限</a>
						<a href="{php echo ifilter_url('status:1');}" class="btn {if $status == 1}btn-primary{else}btn-default{/if}">待接单</a>
						<a href="{php echo ifilter_url('status:2');}" class="btn {if $status == 2}btn-primary{else}btn-default{/if}">已确认</a>
						<a href="{php echo ifilter_url('status:5');}" class="btn {if $status == 5}btn-primary{else}btn-default{/if}">已完成</a>
						<a href="{php echo ifilter_url('status:6');}" class="btn {if $status == 6}btn-primary{else}btn-default{/if}">已取消</a>
					</div>
				</div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-3 col-md-2 control-label">支付状态</label>
			<div class="col-sm-9 col-xs-12">
				<div class="btn-group">
					<div class="btn-group">
						<a href="{php echo ifilter_url('is_pay:-1');}" class="btn {if $is_pay == -1}btn-primary{else}btn-default{/if}">不限</a>
						<a href="{php echo ifilter_url('is_pay:0');}" class="btn {if $is_pay == 0}btn-primary{else}btn-default{/if}">未支付</a>
						<a href="{php echo ifilter_url('is_pay:1');}" class="btn {if $is_pay == 1}btn-primary{else}btn-default{/if}">已支付</a>
					</div>
				</div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-3 col-md-2 control-label">支付方式</label>
			<div class="col-sm-9 col-xs-12">
				<div class="btn-group">
					<div class="btn-group">
						<a href="{php echo ifilter_url('pay_type:');}" class="btn {if $pay_type == ''}btn-primary{else}btn-default{/if}">不限</a>
						<a href="{php echo ifilter_url('pay_type:wechat');}" class="btn {if $pay_type == 'wechat'}btn-primary{else}btn-default{/if}">微信支付</a>
						<a href="{php echo ifilter_url('pay_type:alipay');}" class="btn {if $pay_type == 'alipay'}btn-primary{else}btn-default{/if}">支付宝</a>
						<a href="{php echo ifilter_url('pay_type:credit');}" class="btn {if $pay_type == 'credit'}btn-primary{else}btn-default{/if}">余额支付</a>
						<a href="{php echo ifilter_url('pay_type:delivery');}" class="btn {if $pay_type == 'delivery'}btn-primary{else}btn-default{/if}">货到付款</a>
						<a href="{php echo ifilter_url('pay_type:peerpay');}" class="btn {if $pay_type == 'peerpay'}btn-primary{else}btn-default{/if}">找人代付</a>
					</div>
				</div>
			</div>
		</div>
	{elseif $filter_type == 'is_remind'}
		<input type="hidden" name="is_remind" value="{$is_remind}"/>
		<div class="form-group">
			<label class="col-xs-12 col-sm-3 col-md-2 control-label">处理状态</label>
			<div class="col-sm-9 col-xs-12">
				<div class="btn-group">
					<div class="btn-group">
						<a href="{php echo ifilter_url('is_remind:1');}" class="btn {if $is_remind == 1}btn-primary{else}btn-default{/if}">未处理</a>
						<a href="{php echo ifilter_url('is_remind:2');}" class="btn {if $is_remind == 2}btn-primary{else}btn-default{/if}">已处理</a>
					</div>
				</div>
			</div>
		</div>
	{elseif $filter_type == 'refund_status'}
		<input type="hidden" name="refund_status" value="{$re_status}"/>
		<div class="form-group">
			<label class="col-xs-12 col-sm-3 col-md-2 control-label">处理状态</label>
			<div class="col-sm-9 col-xs-12">
				<div class="btn-group">
					<div class="btn-group">
						<a href="{php echo ifilter_url('refund_status:1');}" class="btn {if $re_status == 1}btn-primary{else}btn-default{/if}">未处理</a>
						<a href="{php echo ifilter_url('refund_status:2');}" class="btn {if $re_status == 2}btn-primary{else}btn-default{/if}">退款中</a>
						<a href="{php echo ifilter_url('refund_status:3');}" class="btn {if $re_status == 3}btn-primary{else}btn-default{/if}">退款成功</a>
					</div>
				</div>
			</div>
		</div>
	{/if}
	<div class="form-group form-inline">
		<label class="col-xs-12 col-sm-3 col-md-2 control-label">其他</label>
		<div class="col-sm-9 col-xs-12">
			{if $_W['is_agent']}
				<select name="agentid" class="select2 js-select2 form-control width-130">
					<option value="0">选择代理区域</option>
					{loop $_W['agents'] $agent}
						<option value="{$agent['id']}" {if $agentid == $agent['id']}selected{/if}>{$agent['area']}</option>
					{/loop}
				</select>
			{/if}
			<select name="sid" class="form-control select2">
				<option value="0" {if $sid == 0}select{/if}>所属线路</option>
				{loop $stores $store}
					<option value="{$store['id']}" {if $sid == $store['id']}selected{/if}>{$store['title']}</option>
				{/loop}
			</select>
			<div style="display: inline-block">
				{php echo tpl_form_field_daterange('addtime', array('start' => date('Y-m-d', $starttime), 'end' => date('Y-m-d', $endtime)));}
			</div>
			<input type="text" name="keyword" value="{$keyword}" class="form-control" placeholder="输入用户名/手机号/订单编号">
			<input type="text" name="uid" value="{if !empty($uid)}{$uid}{/if}" class="form-control" placeholder="用户UID">
		</div>
	</div>
	<div class="form-group">
		<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
		<div class="col-sm-9 col-xs-12">
			<button class="btn btn-primary">筛选</button>
		</div>
	</div>
</form>
<div class="clearfix order-list">
	{if !empty($orders)}
	<div class="col-md-8">
		{loop $orders $order}
		<div class="panel-order">
			<div class="pay-info {$order['pay_type_class']}"></div>
			<div class="panel-heading clearfix">
				<div class="order-info pull-left">
					<span class="serial-sn">
						#<strong>{$order['serial_sn']}</strong>
					</span>
					<span class="store-info">
						<strong>{$stores[$order['sid']]['title']}</strong>
						&nbsp;
					</span>
					<span class="send-time">
						{if $dca['order_type'] == 3}
							<strong>{$tables[$order['table_id']]['title']}桌,{$order['person_num']}人就餐</strong>
						{else}
							<strong>{$table_categorys[$order['table_cid']]['title']},{$order['reserve_time']}就餐,{$order_reserve_types[$order['reserve_type']]['text']}</strong>
						{/if}
						<span class="grayest">（{php echo date('Y-m-d H:i', $order['addtime'])} 下单）</span>
						{if $order['is_pay'] == 1}
							<span>{$pay_types[$order['pay_type']]['text']}</span>
						{/if}
					</span>
				</div>
				<div class="order-status pull-right"><strong class="{$order_status[$order['status']]['color']}">{$order_status[$order['status']]['text']}</strong></div>
			</div>
			<div class="user-info">
				<span class="highlight">{$order['username']}</span>
				<span class="user-phone">{$order['mobile']}</span>
				<a href="{php echo ifilter_url('uid:' . $order['uid']);}" class="greenest pull-right">查看用户历史订单</a>
				<div class="user-location clearfix">
					<span>{$order['address']}</span>
					<a href="javascript:;" class="greenest pull-right hide"><i class="fa fa-map-marker"></i>5.0km</a>
				</div>
			</div>
			<div class="product-info">
				<p class="product-title">
					<span class="highlight">商品信息</span>
					<span class="pull-right greenest toggle-product">展开 <i class="fa fa-angle-up"></i></span>
				</p>
				<div class="product-display hide">
					<div class="remark"><span class="orange">备注：</span>{if !empty($order['note'])}{$order['note']}{else}无{/if}</div>
					<div class="table-order">
						<table class="table">
							<tbody>
							{loop $goods_all[$order['id']] $goods}
								<tr>
									<td class="goods-name">{$goods['goods_title']}</td>
									<td class="goods-price">¥{$goods['goods_unit_price']}</td>
									<td class="goods-num">x{$goods['goods_num']}</td>
									<td class="total-price">¥{$goods['goods_price']}</td>
								</tr>
							{/loop}
							</tbody>
						</table>
					</div>
					{if $order['box_price'] > 0}
					<div class="list-item clearfix">
						<span class="pull-left">餐盒费</span>
						<span class="pull-right">¥{$order['box_price']}</span>
					</div>
					{/if}
					{if $order['pack_fee'] > 0}
					<div class="list-item clearfix">
						<span class="pull-left">包装费</span>
						<span class="pull-right">¥{$order['pack_fee']}</span>
					</div>
					{/if}
					{if $order['delivery_fee'] > 0}
					<div class="list-item clearfix">
						<span class="pull-left">拼车费</span>
						<span class="pull-right">¥{$order['delivery_fee']}</span>
					</div>
					{/if}
					<div class="charge-info">
						<div class="charge-title clearfix">
							<div class="pull-left"><strong>小计</strong></div>
							<div class="pull-right">¥{$order['total_fee']}</div>
						</div>
						<div class="charge-title clearfix">
							<div class="pull-left"><strong>顾客实际支付</strong></div>
							<div class="pull-right">¥{$order['final_fee']}</div>
						</div>
						<div class="total clearfix">
							<div class="pull-left"><span class="highlight">商户预计收入</span></div>
							<div class="pull-right"><span class="highlight">¥{$order['store_final_fee']}</span></div>
						</div>
					</div>
				</div>
			</div>
			<div class="btn-area">
				{if $order['status'] < 5}
					{if $order['status'] == 1}
						<a href="{php echo iurl('order/tangshi/status', array('type' => 'handle', 'id' => $order['id']));}" class="btn btn-primary btn-sm js-post" data-confirm="确定接单吗">接受订单</a>
					{else}
						<a href="{php echo iurl('order/tangshi/status', array('type' => 'end', 'id' => $order['id']));}" class="btn btn-primary btn-sm js-post" data-confirm="确定完成订单吗?">完成订单</a>
					{/if}
					{if $order['is_pay'] == 1 && $order['pay_type'] != 'delivery'}
						<a href="{php echo iurl('order/tangshi/cancel', array('id' => $order['id']));}" class="btn btn-primary btn-sm js-post" data-confirm="确定取消订单并退款?">取消订单并退款</a>
					{else}
						<a href="{php echo iurl('order/tangshi/cancel', array('id' => $order['id']));}" class="btn btn-primary btn-sm js-post" data-confirm="确定取消订单?">取消订单</a>
					{/if}
					{if !$order['is_pay']}
						<a href="{php echo iurl('order/tangshi/pay_status', array('id' => $order['id']));}" class="btn btn-primary btn-sm js-post" data-confirm="确定修改支付状态?">设为已支付</a>
					{/if}
					{if $order['is_remind'] == 1}
						<a href="{php echo iurl('order/tangshi/remind', array('id' => $order['id']));}" class="btn btn-primary btn-sm js-modal">回复催单</a>
					{/if}
				{/if}
				{if $order['refund_status'] == 1}
					<a href="{php echo iurl('order/tangshi/refund_handle', array('id' => $order['id']));}" class="btn btn-primary btn-sm js-post" data-confirm="确定发起退款吗?">发起退款</a>
				{elseif $order['refund_status'] == 2}
					<a href="{php echo iurl('order/tangshi/refund_query', array('id' => $order['id']));}" class="btn btn-primary btn-sm js-post">查询退款进度</a>
				{/if}
				{if $order['refund_status'] > 0 && $order['refund_status'] < 3}
					<a href="{php echo iurl('errander/order/refund_status', array('id' => $order['id']));}" class="btn btn-primary btn-sm js-post" data-confirm="确定设置为已退款吗?">已退款</a>
				{/if}
				<a href="{php echo iurl('order/tangshi/print', array('id' => $order['id']));}" class="btn btn-primary btn-sm js-post" data-confirm="确定打印订单吗?"><i class="fa fa-print"></i> ( {$order['print_nums']} )</a>
				<a href="{php echo iurl('order/tangshi/detail', array('id' => $order['id']));}" target="_blank" class="btn btn-primary btn-sm">详情</a>
			</div>
		</div>
		{/loop}
	</div>
	<div class="col-md-4">
		<div class="panel panel-stat">
			<div class="panel-heading">
				<h3>当日订单概况</h3>
			</div>
			<div class="panel-body">
				<div class="col-md-6">
					<div class="title">已接订单(笔)</div>
					<div class="num-wrapper">
						<a class="num" href="javascript:;">{php echo intval($stat['total_num']);}</a>
					</div>
				</div>
				<div class="col-md-6">
					<div class="title">用户支付金额(元)</div>
					<div class="num-wrapper">
						<a class="num" href="javascript:;">{php echo round($stat['total_price'], 2);}</a>
					</div>
				</div>
			</div>
		</div>
	</div>
	{else}
		<div class="no-result">
			<p>还没有相关数据</p>
		</div>
	{/if}
	<div class="col-md-12">
		{$pager}
	</div>
</div>
<script>
irequire(['laytpl', 'tiny'], function(laytpl, tiny){
	$('.btn-refresh, .btn-notice').click(function(){
		var type = $(this).data('type');
		var value = $(this).find(':checkbox').prop('checked') ? 0 : 1;
		$.post(location.href, {type: type, value: value}, function(){
			location.reload();
		});
		return false;
	});

	{if $_GPC['_status_store_order_refresh'] == 1}
		var sync = setInterval(function(){
			var time = parseInt($('#time-count span').html());
			if(time > 1) {
				time--;
				var html = '<span>' + time + '</span>'  + '秒后';
				$('#time-count').html(html);
			} else {
				location.reload();
			}
		}, 1000);
		if(!$('#time-count span').size()) {
			clearInterval(sync);
		}
	{/if}

	$(document).on('click', '.product-title .toggle-product', function(){
		var $parent = $(this).parents('.panel-order');
		var is_hide = $('.product-display', $parent).hasClass('hide');
		if(is_hide) {
			$('.product-display', $parent).removeClass('hide');
			$(this).html('收起 <i class="fa fa-angle-up"></i>');
		} else {
			$('.product-display', $parent).addClass('hide');
			$(this).html('展开 <i class="fa fa-angle-down"></i>');
		}
	});
});
</script>
{itemplate 'public/footer'}